package com.lemon.smartsafety.utils;

import android.content.Context;
import android.widget.Toast;

import com.baidu.mapapi.cloud.CloudListener;
import com.baidu.mapapi.cloud.CloudManager;
import com.baidu.mapapi.cloud.CloudPoiInfo;
import com.baidu.mapapi.cloud.CloudSearchResult;
import com.baidu.mapapi.cloud.DetailSearchResult;
import com.baidu.mapapi.cloud.NearbySearchInfo;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.model.LatLngBounds;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/8/18 13:31
 * 修改人：Fargo
 * 修改时间：2016/8/18 13:31
 * 修改备注：    周边雷达
 */
public class NearbySearchUtil implements CloudListener {

    private Context context;

    public NearbySearchUtil(Context context) {
        this.context = context;
    }

    private CallBackInterface mCallBackInterface=null;

    @Override
    public void onGetSearchResult(CloudSearchResult result, int i) {
        if (result != null && result.poiList != null
                && result.poiList.size() > 0) {
            LogUtils.LOGE("onGetSearchResult, result length: " + result.poiList.size());

            LatLng ll;
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            for (CloudPoiInfo info : result.poiList) {
                ll = new LatLng(info.latitude, info.longitude);
                LogUtils.LOGE(info.address);
                LogUtils.LOGE(info.toString());
            }

        }
    }

    @Override
    public void onGetDetailSearchResult(DetailSearchResult result, int i) {
        if (result != null) {
            if (result.poiInfo != null) {
                Toast.makeText(context, result.poiInfo.title,
                        Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(context,
                        "status:" + result.status, Toast.LENGTH_SHORT).show();
            }
        }
    }

    public interface CallBackInterface {
        public void callBackFunction();

    }

     public void search(LatLng latLng,CallBackInterface callBackInterface){

         mCallBackInterface=callBackInterface;
         CloudManager.getInstance().init(this);

         NearbySearchInfo info = new NearbySearchInfo();
         info.ak = "iWrIbm5G9HWZ731yOGx2aUVu2mBNaWk0";
         info.geoTableId = 8419208;
         info.radius = 1000;
         info.location = String.valueOf(latLng.latitude+latLng.longitude);
         CloudManager.getInstance().nearbySearch(info);

     }




    public void onDestroy() {
        CloudManager.getInstance().destroy();
    }




}
